import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-07-25
 * Time:16:13
 */
@WebServlet(name = "PathServlet", urlPatterns = "/pathServlet")
public class PathServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 服务端解析转发路径时,不使用绝对路径
        // 默认路径为http://ip:port/工程路径/
        // 路径的第一个'/'会被解析为http://ip:port/工程路径/
        req.getRequestDispatcher("b1/b2/base.html").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
